const { insertData, findData, updateData, deleteOneData, requstPromise, randomWord } = require('../utils')
const { updateUserInfo } = require('./user')
const crypto = require('crypto')

const Exchange = {
    // 
    async addExchange(option) {
        const { goodsId, goodsName, goodsPic, goodsIntegral, name, address, phone, } = option
        return requstPromise(await insertData('camluniExchange', {
            id: randomWord(false, 43),
            goodsId, // 商品id
            goodsName, // 商品名称
            goodsPic, // 商品图片
            goodsIntegral, // 兑换所用积分
            name, // 兑换人姓名
            address, // 兑换人地址
            phone, // 兑换人地址
        }))
    },

    // 删除指定id
    async deleteExchange(id) {
        return requstPromise(await deleteOneData('camluniExchange', { id }))
    },

    // 
    async editExchange(option) {
        const { id, ...data } = option
        return requstPromise(await updateData('camluniExchange', { id }, { ...data }))
    },

    // 获取列表
    async findExchange(option) {
        return requstPromise(await findData('camluniExchange', { ...option }))
    },
}

module.exports = Exchange
